<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>callback</title>
    <script type="text/javascript" src="./plugins/vue/dist/vue.min.js"></script>
    <script type="text/javascript" src="./plugins/axios/dist/axios.min.js"></script>
    <script type="text/javascript" src="./js/common.js"></script>
</head>
<body>
<div id="app">

</div>
</body>
<script>
    new Vue({
        el:"#app",
        mounted() {
            //获取?后面的参数
            let param=getParam();
            //获取授权码
            let code=param.code;
            console.debug(param);
            //通过授权码获取token值
            this.$http.post("/wechat/gotoBinderOrLogin",param).then((res)=>{
                //如果后台响应了openid就意味着必须跳转到绑定界面
                console.debug(res.data);
                let {openid,token,loginUser}=res.data;
                if(openid){//如果openid有值跳转到绑定界面
                    location.href="binder.html?openid="+openid;
                }else{

                    //设置到浏览器
                    localStorage.setItem("token",token);
                    localStorage.setItem("loginUser",JSON.stringify(loginUser));
                    //跳转到首页
                    location.href="index.html";
                }

            });
        }
    })
</script>
</html>